﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Clustering_IA_Project
{
    public struct Request
    {
        public string user;
        public string webPage;
        public string date;
    }

    /// <summary>
    /// Classe che legge gli Xml per le richieste di recommainder
    /// </summary>
    class ReadRequest
    {
        /// <summary>
        /// Metodo che legge tutti le richieste pervenute tramite file xml
        /// </summary>
        /// <param name="path">path del file da leggere</param>
        /// <returns></returns>
        public Request ReadXML(String pageName)
        {
            Request rq = new Request();
            //leggo il file XLM
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(pageName);

            XmlNodeList luser = xmlDoc.GetElementsByTagName("user");
            XmlNodeList lwebPage = xmlDoc.GetElementsByTagName("webpage");
            XmlNodeList ldate = xmlDoc.GetElementsByTagName("date");
            
            rq.user = (xmlDoc.GetElementsByTagName("user"))[0].InnerText.Trim();
            rq.webPage = (xmlDoc.GetElementsByTagName("webpage"))[0].InnerText.Trim();
            rq.date = (xmlDoc.GetElementsByTagName("date"))[0].InnerText.Trim();
            
            return rq;
        }
    }
}
